package com.detech.sbom.business.user.controller;

import com.detech.sbom.base.annotation.Lock;
import com.detech.sbom.base.domain.R;
import com.detech.sbom.base.domain.RE;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.time.LocalTime;

/**
 * 测试分布式锁的样例
 */
@Api(tags = "测试分布式锁的样例")
@RestController
@RequestMapping("/demo/redisLock")
public class RedisLockController {

    /**
     * 测试lock 注解
     */
    @ApiOperation("测试lock 注解")
    @Lock
    @PostMapping("/testLock")
    public RE testLock(String key, String value) {
        System.out.println("start:" + key + ",time:" + LocalTime.now().toString());
        try {
            Thread.sleep(3000);
        } catch (InterruptedException e) {
            e.printStackTrace();
        }
        System.out.println("end :" + key + ",time:" + LocalTime.now().toString());
        return R.ok(value);
    }


}
